﻿package mortal.game.view.copy.GroupTowerCopy
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.global.*;
    import extend.language.*;
    import mortal.common.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.*;
    import mortal.game.view.copy.GroupTowerCopy.data.*;
    import mortal.game.view.copy.GroupTowerCopy.panel.*;
    import mortal.game.view.copy.copyFailWin.*;
    import mortal.game.view.copy.singleTowerCopy2.data.*;
    import mortal.game.view.copy.singleTowerCopy2.panel.*;
    import mortal.game.view.guide.*;
    import mortal.mvc.core.*;

    public class GroupTowerCopyController extends CopyControllerBase
    {
        private var _miniMapView:SingleTowerInfoPanel;

        public function GroupTowerCopyController()
        {
            return;
        }// end function

        override public function enterCopy(param1:TCopy) : void
        {
            var arr:Array;
            var copy:* = param1;
            super.enterCopy(copy);
            if (GameController.copy.groupCopy.isViewShow)
            {
                GameController.copy.groupCopy.view.hide();
            }
            if (ECopyType._ECopyTypeTower == copy.type)
            {
                if (!Cache.instance.buff.isHasBuffByType(EBuffType._EBuffTypeExp))
                {
                    var showItem:* = function (param1:Array) : void
            {
                var _loc_2:* = new GuideUseItemData();
                _loc_2.itemData = param1[0];
                _loc_2.isGuideToUseItem = true;
                _loc_2.isCountdown = false;
                _loc_2.showTxt = "" + Language.getString(70930);
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideShowBackPackItem, _loc_2));
                return;
            }// end function
            ;
                    arr = Cache.instance.pack.backPackCache.getItemsByGroupCategoryAndType(EGroup._EGroupProp, EProp._EPropDrug, EDrug._EDrugMoreExp);
                    if (arr.length)
                    {
                    }
                }
            }
            Cache.instance.copy.groupTower.isEnd = false;
            return;
        }// end function

        private function onLeaveCopy(param1:TCopy) : void
        {
            var _loc_2:SBuffUpdate = null;
            var _loc_3:SBuff = null;
            if (param1 && ECopyType._ECopyTypeTower == param1.type)
            {
                _loc_2 = new SBuffUpdate();
                _loc_2.op = EBuffUpdateType._EBuffUpdateTypeRemove;
                _loc_3 = new SBuff();
                _loc_3.buffId = 23000041;
                _loc_2.buffs = [_loc_3];
                cache.buff.updateBuff(_loc_2);
                NetDispatcher.dispatchCmd(ServerCommand.BufferUpdate, cache.buff.showBuffArray);
                if (SingleTowerInfoPanel.isView)
                {
                    SingleTowerInfoPanel.instance.hide();
                }
                if (SingleTowerPassPanel.isView)
                {
                    SingleTowerPassPanel.instance.hide();
                }
            }
            return;
        }// end function

        public function addMiniMap() : void
        {
            if (this._miniMapView == null)
            {
                this._miniMapView = UIFactory.getUICompoment(SingleTowerInfoPanel);
            }
            this._miniMapView.show(500, 500);
            this._miniMapView.x = Global.stage.stageWidth - 50 - 238;
            this._miniMapView.y = 116;
            return;
        }// end function

        override protected function initServer() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.Copy_LeaveCopy, this.onLeaveCopy);
            EventUtil.addSelfEvent(EventName.SingleTowerGetFirstRwInfo, this.getFirstRwInfo, true);
            EventUtil.addSelfEvent(EventName.SingleTowerGetFirstRw, this.getFirstRw, true);
            EventUtil.addSelfEvent(EventName.SingleTower2EnterNextCk, this.onEnterNextNew, true);
            EventUtil.addNetEvent(ServerCommand.SingleTowerCopyInfoRes, this.enterInfoShowNew, true);
            EventUtil.addNetEvent(ServerCommand.SingleTowerCopyEnd, this.onCopyEndNew, true);
            return;
        }// end function

        private function initHd(param1:Object) : void
        {
            GroupTowerFaildWin.instance.show();
            return;
        }// end function

        override protected function addListeners() : void
        {
            this.addEvs(true);
            return;
        }// end function

        override protected function removeListeners() : void
        {
            this.addEvs(false);
            return;
        }// end function

        private function addEvs(param1:Boolean) : void
        {
            EventUtil.addNetEvent(ServerCommand.GroupTowerCopyPass, this.onPassOne, param1);
            EventUtil.addSelfEvent(EventName.GroupTowerEnterNextLevel, this.onEnterNext, param1);
            EventUtil.addNetEvent(ServerCommand.GroupTowerCopyHurtInfo, this.updateHurtList, param1);
            EventUtil.addSelfEvent(EventName.ChangeScene, this.onGuanChange, param1);
            EventUtil.addSelfEvent(EventName.SingleTower2Enter, this.onEnterNext, param1);
            return;
        }// end function

        override public function leaveCopy() : void
        {
            super.leaveCopy();
            this.clear();
            return;
        }// end function

        private function clear() : void
        {
            if (GroupTowerPassWin.hasInstance && GroupTowerPassWin.instance.isHide == false)
            {
                GroupTowerPassWin.instance.hide();
            }
            if (GroupTowerFaildWin.hasInstance && GroupTowerFaildWin.instance.isHide == false)
            {
                GroupTowerFaildWin.instance.hide();
            }
            if (SingleTowerInfoPanel.isView)
            {
                SingleTowerInfoPanel.instance.hide();
            }
            Cache.instance.copy.groupTower.isEnd = false;
            return;
        }// end function

        private function onInfoRes(param1:Object) : void
        {
            var _loc_2:Array = null;
            GroupTowerCopyInfoPanel.instance.show();
            GroupTowerCopyInfoPanel.instance.updateInfo(param1 as SGroupTowerMsg);
            if (Cache.instance.copy.groupTower.towerInfo.result && GroupTowerCopyUtil.TotalLevel == Cache.instance.copy.groupTower.towerInfo.level)
            {
                _loc_2 = GroupTowerCopyUtil.getFailPassInfo();
                GroupTowerFaildWin.instance.show();
                GroupTowerFaildWin.instance.updateFailInfo(_loc_2);
            }
            return;
        }// end function

        private function onPassOne(param1:Object) : void
        {
            this.countDown(param1);
            return;
        }// end function

        private function countDown(param1:Object) : void
        {
            return;
        }// end function

        private function onEnterNext(event:DataEvent) : void
        {
            var _loc_2:* = event.data;
            var _loc_3:* = _loc_2.copyCode;
            var _loc_4:* = _loc_2.level;
            if (_loc_4 != 0)
            {
                GameProxy.tower.goToGroupTowerLevel(_loc_3, (_loc_4 + 1));
            }
            return;
        }// end function

        private function updateHurtList(param1:Object) : void
        {
            return;
        }// end function

        private function onGuanChange(param1:Object) : void
        {
            if (SingleTowerInfoPanel.isView)
            {
                GroupTowerCopyUtil.isStarTime = true;
                GroupTowerCopyInfoPanel.instance.updateGuanTxt();
            }
            return;
        }// end function

        private function onTimeEnd(param1:Object) : void
        {
            var _loc_3:Array = null;
            if (GroupTowerPassWin.hasInstance && GroupTowerPassWin.instance.isHide == false)
            {
                GroupTowerPassWin.instance.hide();
            }
            if (SingleTowerInfoPanel.isView)
            {
                SingleTowerInfoPanel.instance.hide();
            }
            var _loc_2:* = Cache.instance.copy.groupTower.towerInfo;
            if (GroupTowerCopyUtil.TotalLevel != _loc_2.level || GroupTowerCopyUtil.TotalLevel == _loc_2.level && _loc_2.result == false)
            {
                _loc_3 = GroupTowerCopyUtil.getFailPassInfo();
                GroupTowerFaildWin.instance.show();
                GroupTowerFaildWin.instance.updateFailInfo(_loc_3);
            }
            return;
        }// end function

        private function getFirstRwInfo(event:DataEvent) : void
        {
            var _loc_2:* = event.data as TCopy;
            var _loc_3:* = _loc_2.code;
            GameProxy.copy.getTowerCopy4FirstRewardGetInfo(_loc_3);
            return;
        }// end function

        private function getFirstRw(event:DataEvent) : void
        {
            var _loc_2:* = event.data;
            var _loc_3:* = _loc_2.code;
            var _loc_4:* = _loc_2.lv;
            GameProxy.copy.getTowerCopy4FirstReward(_loc_3, _loc_4);
            return;
        }// end function

        private function enterCopy2(event:DataEvent) : void
        {
            var _loc_2:* = event.data.tcopy as TCopy;
            var _loc_3:* = _loc_2.code;
            var _loc_4:* = int(event.data.lv);
            GameProxy.copy.enterTowerCopy4(_loc_3, _loc_4);
            return;
        }// end function

        private function onEnterNextNew(event:DataEvent) : void
        {
            var _loc_2:* = Cache.instance.copy.groupTower.singleTowerInfo;
            var _loc_3:* = _loc_2.level;
            var _loc_4:* = _loc_2.copyCode;
            SingleTowerCopyUtil.curLv = _loc_3;
            GameProxy.copy.goToTowerCopy4Level(_loc_4, _loc_3);
            return;
        }// end function

        private function enterInfoShowNew(param1:Object) : void
        {
            var _loc_2:* = Cache.instance.copy.groupTower.singleTowerInfo;
            SingleTowerInfoPanel.instance.updateInfo(_loc_2);
            SingleTowerInfoPanel.instance.show();
            SingleTowerPassPanel.canShow = true;
            return;
        }// end function

        private function onCopyEndNew(param1:Object) : void
        {
            var _loc_3:STowerCopy4EndMsg = null;
            var _loc_2:* = SingleTowerPassPanel.canShow;
            if (_loc_2)
            {
                _loc_3 = Cache.instance.copy.groupTower.singleEndInfo;
                if (_loc_3.result == 0)
                {
                    CopyFailBaseWin.instance.show();
                    CopyFailBaseWin.instance.tipsImageUrl = ImagesConst.copyFailBaseWinTxt_2;
                }
                else
                {
                    SingleTowerPassPanel.canShow = false;
                    SingleTowerPassPanel.instance.show();
                    SingleTowerPassPanel.instance.updateInfo(_loc_3);
                }
            }
            if (SingleTowerInfoPanel.isView)
            {
                SingleTowerInfoPanel.instance.stopTime();
            }
            return;
        }// end function

    }
}
